package edu.bbu.bibliospring.api.cdiassembler;

import edu.bbu.bibliospring.api.resources.TestResource;
import edu.bbu.bibliospring.backend.model.Location;
import edu.bbu.bibliospring.common.dto.LocationDto;
import org.apache.log4j.Logger;

/**
 * Created by erika on 6/13/14.
 * Assembler class transforming the model and dto of the Location entity
 */
public class LocationAssembler implements Assembler<Location, LocationDto> {

    private static final Logger LOG = Logger.getLogger(TestResource.class);

    @Override
    public Location createModel() {
        LOG.info("LocationAssembler - new Location created");
        return new Location();
    }

    @Override
    public LocationDto createDto() {
        LOG.info("LocationAssembler - new LocationDto created");
        return new LocationDto(Location.class.getName());
    }

    @Override
    public LocationDto modelToDto(Location model) {
        LOG.info("LocationAssembler - modelToDto");
        LocationDto dto = createDto();
        dto.setId(model.getId());
        dto.setLibraryName(model.getLibraryName());
        dto.setAddress(model.getAddress());
        return dto;
    }

    @Override
    public Location dtoToModel(LocationDto dto) {
        LOG.info("LocationAssembler - dtoToModel");
        Location location = createModel();
        location.setId(dto.getId());
        location.setLibraryName(dto.getLibraryName());
        location.setAddress(dto.getAddress());
        return location;
    }
}
